<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>风景相册</title>
    <style type="text/css">
        *{
            padding: 0;
            margin: 0;
        }
        ul{
            list-style: none;
            overflow: hidden;
        }
        ul li{
            float: left;
            width: 50px;
            height: 50px;
            margin-left: 10px;
            margin-top: 20px;
            border: 2px solid #fff;
        }
        ul li.active{
            border-color: red;
        }
    </style>
</head>
<body>
    <img src="images/img01.jpg" id="bigImg">
    <ul>
        <li class="active">
            <a href="">
                <img src="images/img01.jpg" width="46" class="smallImg">
            </a>
        </li>
        <li>
            <a href="">
                <img src="images/img02.jpg" width="46"  class="smallImg">
            </a>
        </li>
        <li>
            <a href="">
                <img src="images/img03.jpg" width="46"  class="smallImg">
            </a>
        </li>
    </ul>
    <script type="text/javascript">
        // 1.获取事件源
        var bigImg = document.getElementById('bigImg');
        var smallImgs = document.getElementsByClassName('smallImg');

        for(var i = 0; i < smallImgs.length; i++){
            // 遍历集合,给每个img标签添加事件
            smallImgs[i].onmouseover = function(){
                // 在悬浮到每个li标签之前,先把所有的li标签的类名都置为空值
                for(var j = 0; j < smallImgs.length; j++){
                    smallImgs[j].parentNode.parentNode.setAttribute('class','');
                }
                // 修改大图的src属性值
                var smallImgSrc = this.getAttribute('src');
                bigImg.setAttribute('src',smallImgSrc);
                // 给鼠标悬浮的img标签的父标签添加类
                this.parentNode.parentNode.setAttribute('class','active');
            }
        }

    </script>
</body>
</html>